/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.gestion_mouvement;

import model.util.Direction;
import model.util.Couleur;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author ANNAS
 */
public abstract class MouvementValidator {
    protected static ArrayList<Direction>lesDirectionsValides = new ArrayList<Direction>();
    static{
        MouvementValidator.lesDirectionsValides.add(Direction.SUD_EST);
        MouvementValidator.lesDirectionsValides.add(Direction.SUD_OUEST);
        MouvementValidator.lesDirectionsValides.add(Direction.NORD_EST);
        MouvementValidator.lesDirectionsValides.add(Direction.NORD_OUEST);
    }
    
    protected boolean valid;
    protected ArrayList<IPiece> pieceAManger;
    protected Direction direction;
    protected Couleur couleur;
    protected ICase depart;
    protected ICase arrive;
    protected int longueurChemin;

    public MouvementValidator() {
        this.pieceAManger = new ArrayList<IPiece>();
        valid = false;
    }

    protected List<ICase> getChemin() throws Exception
    {
        ArrayList<ICase> leChemin = new ArrayList<ICase>();
        Direction dir =this.getDepart().getDirectionVers(this.getArrive());
        if(!MouvementValidator.lesDirectionsValides.contains(dir))
            throw new Exception("Le déplacement n'est pas en diagonale!");
        int j=0;ICase c = this.getDepart();
        while(j<this.longueurChemin && c!=null && c!=this.getArrive())
        {
            c = c.getVoisine(dir);
            leChemin.add(c);
            j++;
        }
        if(!c.equals(this.getArrive()))
            throw new Exception("Le chemin de la case depart à la case arrive n existe pas");
        return leChemin;
        
    }
    protected abstract void validationMouvement();
    /**
     * @return the valid
     */
    public boolean isValid() {
        this.validationMouvement();
        return valid;
    }

    public boolean peutManger()
    {
        return !this.getPieceAManger().isEmpty();
    }

    /**
     * @return the pieceAManger
     */
    public ArrayList<IPiece> getPieceAManger() {
        return pieceAManger;
    }

    /**
     * @param pieceAManger the pieceAManger to set
     */
    public void setPieceAManger(ArrayList<IPiece> pieceAManger) {
        this.pieceAManger = pieceAManger;
    }

    /**
     * @return the direction
     */
    public Direction getDirection() {
        return direction;
    }

    /**
     * @param direction the direction to set
     */
    public void setDirection(Direction direction) {
        this.direction = direction;
    }

    /**
     * @return the couleur
     */
    public Couleur getCouleur() {
        return couleur;
    }

    /**
     * @param couleur the couleur to set
     */
    public void setCouleur(Couleur couleur) {
        this.couleur = couleur;
    }

    /**
     * @return the depart
     */
    public ICase getDepart() {
        return depart;
    }

    /**
     * @param depart the depart to set
     */
    public void setDepart(ICase depart) {
        this.depart = depart;
    }

    /**
     * @return the arrive
     */
    public ICase getArrive() {
        return arrive;
    }

    /**
     * @param arrive the arrive to set
     */
    public void setArrive(ICase arrive) {
        this.arrive = arrive;
    }
    
    
}
